
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.model.UploadFormat;
import com.dps.omc.service.IUploadFormatService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class UploadFormatAction extends AbstractAdminController<IUploadFormatService>{

    @Autowired
    private IUploadFormatService uploadFormatService;
    
    @RequestMapping(value="/uploadformat/list")
    public String list(UploadFormat uploadFormat, ModelMap model, PageParam pageParam, HttpServletRequest request, HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(uploadFormat); 	
    	BizData4Page<UploadFormat> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("uploadFormat", uploadFormat);
    	return "/module/uploadformat/list";
    }    
    
    @RequestMapping(value="/uploadformat/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("uploadFormat", new UploadFormat());
        return "module/uploadformat/edit";
    }    
    
    @RequestMapping(value="/uploadformat/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	UploadFormat uploadFormat = uploadFormatService.fetch(id);
    	model.addAttribute("uploadFormat", uploadFormat);
        return "module/uploadformat/edit";
    }    
    
    @RequestMapping(value="/uploadformat/save")
    @ResponseBody
    public String save(HttpServletRequest request,UploadFormat uploadFormat){
		boolean isAddNew = StringUtils.isBlank(uploadFormat.getId())?true:false;
		if(isAddNew)
		{
			uploadFormat.setId(IdGenerator.createNewId());
			uploadFormatService.add(uploadFormat);
		}
		else
		{
			uploadFormatService.update(uploadFormat);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/uploadformat/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	uploadFormatService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(UploadFormat uploadFormat)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("format", uploadFormat.getFormat());		
		conditions.put("createDate", uploadFormat.getCreateDate());		
		conditions.put("createrId", uploadFormat.getCreaterId());		
		conditions.put("createrName", uploadFormat.getCreaterName());		
    	return conditions;
    }

    @Override
    protected IUploadFormatService getMainService() {
        return uploadFormatService;
    }

    @Override
    protected String getMainObjName() {
        return "uploadformat";
    }

    @Override
    protected String getViewTitle() {
        return "uploadformat";
    }
}
